package com.itheima.service.cargo.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.cargo.ProductDao;
import com.itheima.domain.cargo.Product;
import com.itheima.domain.cargo.ProductExample;
import com.itheima.service.cargo.ProductService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
public class ProductServiceImpl implements ProductService {
    //一定注意Dao的所有引入都是用@Autowired
    @Autowired
    private ProductDao productDao;



    @Override
    public void save(Product product) {
        productDao.insertSelective(product);
    }

    @Override
    public void update(Product product) {
        productDao.updateByPrimaryKeySelective(product);
    }

    @Override
    public void delete(String id) {
        productDao.deleteByPrimaryKey(id);
    }

    @Override
    public Product findById(String id) {
        return productDao.selectByPrimaryKey(id);
    }

    @Override
    public List<Product> findAll(ProductExample example) {
        return productDao.selectByExample(example);
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize, ProductExample example) {

        PageHelper.startPage(pageNum,pageSize);

        List<Product> productList = productDao.selectByExample(example);
        return new PageInfo(productList,10);

    }
}
